;
;
;	STATIC LOADER FOR SYSTEM MONITOR RELEASE A.01
;
;   ****Donated to the Pascal/Z Users Group,July 1980****
;
MAP	EQU	1000H
ZERO	EQU	2000H
LOCALE	EQU	3F00H
;
SIZE	EQU	LOCALE
VWORK	EQU	LOCALE+2
MWORK	EQU	LOCALE+4
CWORK	EQU	LOCALE+6
TWORK	EQU	LOCALE+8
DWORK	EQU	LOCALE+10
VIDADD	EQU	LOCALE+12
PATCH1	EQU	LOCALE+14
PATCH2	EQU	LOCALE+16
PATCH3	EQU	LOCALE+18
PATCH4	EQU	LOCALE+20
PATCH5	EQU	LOCALE+22
CPTCH1	EQU	LOCALE+24
CPTCH2	EQU	LOCALE+26
CPTCH3	EQU	LOCALE+28
CPTCH4	EQU	LOCALE+30
;
;	CP/M LINKAGES
;
BDOS	EQU	05H
BOUT	EQU	9
BINP	EQU	10
;
;	START
;
START	LD	SP,MAP
	CALL	INPUT
	CALL	SETUP
LOOP	CALL	CHANGE
	CALL	UPDATE
	JR	NZ,LOOP
	CALL	SETVID
	CALL	SETIO
	CALL	SETCAS
	CALL	SETRAM
	CALL	MOVE
	LD	HL,(JUMP)
	JP	(HL)
;
;	SET RAM MEMORY LOCATIONS
;
SETRAM	LD	IX,(VWORK)
	CALL	SETADD
	LD	IX,(MWORK)
	CALL	SETADD
	CALL	ISTADD
	LD	IX,(CWORK)
	CALL	SETADD
	CALL	ISTADD
	LD	IX,(TWORK)
	CALL	SETADD
	LD	IX,(DWORK)
	CALL	SETADD
	RET
;
;	SET RAM ROUTINE
;
SETADD	LD	BC,2000H
	ADD	IX,BC
STA1	LD	C,(IX)
	LD	B,(IX+1)
	LD	HL,(WORK)
	ADD	HL,BC
	LD	(IX),L
	LD	(IX+1),H
	RET
;
ISTADD	INC	IX
	INC	IX
	JR	STA1
;
;	SET VIDEO RAM
;
SETVID	LD	IX,(VIDADD)
	LD	BC,2000H
	ADD	IX,BC
	LD	HL,(VIDEO)
	LD	(IX),L
	LD	(IX+1),H
	LD	BC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PRINTER BUSY ASK
	CALL	YENTER
	JR	C,IP12
	LD	A,L
	LD	(BUSY),A
	OR	A
	JR	Z,IP16
;
IP13	LD	HL,MSG14	;PRINTER BUSY PORT
	LD	IX,LBPORT
	CALL	BENTER
	JR	C,IP13
	JR	Z,IP14
	LD	A,L
	LD	(LBPORT),A
;
IP14	LD	HL,MSG15	;PRINTER BUSY POLARITY
	LD	IX,LBPOL
	CALL	PENTER
	JR	C,IP14
	JR	Z,IP15
	LD	A,L
	LD	(LBPOL),A
;
IP15	LD	HL,MSG16	;PRINTER BUSY MASK
	LD	IX,LBMASK
	CALL	BENTER
	JR	C,IP15
	JR	Z,IP16
	LD	A,L
	LD	(LBMASK),A
;
IP16	LD	HL,MSG17	;PRINTER DATA PORT
	LD	IX,LDPORT
	CALL	BENTER
	JR	C,IP16
	JR	Z,IP17
	LD	A,L
	LD	(LDPORT),A
;
IP17	LD	HL,MSG18	;PRINTER DATA POLARITY
	LD	IX,LDPOL
	CALL	PENTER
	JR	C,IP17
	JR	Z,IP18
	LD	A,L
	LD	(LDPOL),A
;
IP18	LD	HL,MSG19	;CASSETTE BASE
	LD	IX,TPBASE
	CALL	BENTER
	JR	C,IP18
	JR	Z,IP19
	LD	A,L
	LD	(TPBASE),A
;
IP19	LD	HL,MSG20	;DONE?
	CALL	YENTER
	JR	C,IP19
	LD	A,L
	OR	A
	JP	NZ,INPUT
;
IP20	LD	HL,MSG21	;JUMP ADDRESS
	LD	IX,JUMP
	CALL	AENTER
	JR	C,IP20
	RET	Z
	LD	(JUMP),HL
	RET
;
;	SET THE IO PATCHES
;
SETIO	LD	IX,(PATCH1)
	LD	BC,2000H
	ADD	IX,BC
	LD	A,(SPORT)
	LD	(IX+1),A
	LD	A,(SMASK)
	LD	(IX+3),A
	LD	(IX+4),0EEH
	LD	(IX+5),A
	LD	A,(SPOL)
	OR	A
	JR	Z,ST1
	LD	(IX+4),0
	LD	(IX+5),0
;
ST1	LD	IX,(PATCH2)
	ADD	IX,BC
	LD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	H,L
	LD	L,0
	EX	DE,HL
	LD	HL,(BIAS)
	ADD	HL,DE
	EX	DE,HL
	LD	HL,(SIZE)
	LD	C,L
	LD	B,H
	LD	HL,ZERO
	LDIR
	RET
;
;	VARIABLES
;
WORK	DEFW	0FD00H
VIDEO	DEFW	0CC00H
PAGE	DEFB	0D0H
BIAS	DEFW	0
JUMP	DEFW	0
SPORT	DEFB	0
SPOL	DEFB	1
SMASK	DEFB	80H
DPORT	DEFB	1
DPOL	DEFB	1
LSPORT	DEFB	2
LSPOL	DEFB	1
LSMASK	DEFB	80H
BUSY	DEFB	1
LBPORT	DEFB	3
LBPOL	DEFB	1
LBMASK	DEFB	80H
LDPORT	DEFB	4
LDPOL	DEFB	1
TPBASE	DEFB	60H
;
;	MESSAGES
;
MSG1	DEFB	0CH,'SYSTEM MONITOR LOADER A.01',0DH,0AH,0AH
	DEFB	'ENTER THE DATA AS PROMPTED.',0DH,0AH
	DEFB	'AN IMMEDIATE CARRIAGE RETURN WILL ALLOW'
	DEFB	0DH,0AH,'THE DEFAULT TO STAND.',0DH,0AH,0AH
	DEFB	'ENTER MONITOR BASE PAGE NUMBER$'
MSG2	DEFB	0DH,0AH,0AH
	DEFB	'ENTER BIAS ADDRESS$'
MSG3	DEFB	0DH,0AH,0AH
	DEFB	'ENTER VIDEO RAM BASE ADDRESS$'
MSG4	DEFB	0DH,0AH,0AH
	DEFB	'ENTER MONITOR VARIABLE RAM BASE$'
MSG5	DEFB	0DH,0AH,0AH
	DEFB	'ENTER THE KEYBOARD DRIVER VALUES'
	DEFB	0DH,0AH,'   STATUS PORT NUMBER$'
MSG6	DEFB	0DH,0AH,'   STATUS POLARITY(P/N)$'
MSG7	DEFB	0DH,0AH,'   STATUS MASK$'
MSG8	DEFB	0DH,0AH,'   DATA PORT NUMBER$'
MSG9	DEFB	0DH,0AH,'   DATA POLARITY(P/N)$'
MSG10	DEFB	0DH,0AH,0AH,'ENTER THE PRINTER DRIVER VALUES'
	DEFB	0DH,0AH,'   STATUS PORT NUMBER$'
MSG11	DEFB	0DH,0AH,'   STATUS POLARITY(P/N)$'
MSG12	DEFB	0DH,0AH,'   STATUS MASK$'
MSG13	DEFB	0DH,0AH,'DOES PRINTER HAVE ADDITIONAL BUSY'
	DEFB	' PORT ASSIGNED? (Y/N)$'
MSG14	DEFB	0DH,0AH,'   BUSY PORT NUMBER$'
MSG15	DEFB	0DH,0AH,'   BUSY POLARITY(P/N)$'
MSG16	DEFB	0DH,0AH,'   BUSY MASK$'
MSG17	DEFB	0DH,0AH,'   DATA PORT NUMBER$'
MSG18	DEFB	0DH,0AH,'   DATA POLARITY(P/N)$'
MSG19	DEFB	0DH,0AH,0AH,'CASSETTE DRIVER PORT BASE$'
MSG20	DEFB	0DH,0AH,0AH,'DO YOU WANT TO RESTART'
	DEFB	' THE INPUT PROCESS?(Y/N)$'
MSG21	DEFB	0DH,0AH,0AH,'COMPLETION JUMP ADDRESS$'
DFLT1	DEFB	' [DEFAULT = $'
DFLT2	DEFB	' ] $'
BTFLD	DEFB	'00$'
BUFADD	DEFB	80H
	DEFS	81H
	END	START
 